﻿using Logging.Entities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

namespace Logging.LogXML
{
    public class LoggingXML : ILogService
    {
        public String NameApplication
        {
            get;
            private set;
        }

        public String PathApplication
        {
            get;
            private set;
        }

        public LoggingXML(String nameApplication, String pathApplication)
        {
            NameApplication = nameApplication;
            PathApplication = pathApplication;
        }

        #region ILogService Membres

        public void WriteLog(Utils.LogTrace log)
        {
            String dateDay = DateTime.Now.ToShortDateString().Replace('/', '_');
            String path = PathApplication + @"\" + NameApplication + @"_" + dateDay + @".xml";
            TRACE_APPLICATION trace = log.CreateTrace();

            ReadAndWrite.ReadAndWriteXML r = new ReadAndWrite.ReadAndWriteXML(typeof(TRACE_APPLICATION), path);
            r.Save<TRACE_APPLICATION>(trace);
        }

        #endregion
    }
}
